# -*- coding:utf-8 -*-
# coding:utf-8
import scrapy

from tutorial.items import DmozItem
from scrapy.utils.response import open_in_browser
from scrapy import log

class DmozSpider(scrapy.Spider):
    name = "58"
    allowed_domains = ["58.com"]
    start_urls = [
        "http://nj.58.com/"
    ]

    def parse(self, response):
        for sel in response.xpath('//div[@class="colWrap"]/*'):
            for each_a in sel.xpath('//a[@href]'):
                item = DmozItem()
                # item['title'] = sel.xpath('a[@href]/text()').extract()[0].encode('utf-8')
                item['title'] = each_a.xpath('text()').extract()
                item['link'] = each_a.xpath('@href').extract()
                item['desc'] = each_a.xpath('@tongji_tag').extract()
                yield item

    def parse_details(self, response):
        open_in_browser(response)